package com.payment.ktb.view;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;
import com.flyco.animation.Attention.Tada;
import com.flyco.dialog.widget.base.BaseDialog;
import com.payment.ktb.Interface.HttpCallbackListener;
import com.payment.ktb.R;
import com.payment.ktb.activity.main4.CardWrapActivity;
import com.payment.ktb.activity.main4.CardWrapEmptyActivity;
import com.payment.ktb.constants.HttpActions;
import com.payment.ktb.constants.HttpUrls;
import com.payment.ktb.utils.AlertDialogUtils;
import com.payment.ktb.utils.HttpUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by admin on 2017/10/30.
 */

public


class SecKillSuccessDialog extends BaseDialog<com.payment.ktb.view.SecKillSuccessDialog> {

    @BindView(R.id.rl_main1_seckill_success_del)
    RelativeLayout rl_main1_seckill_success_del;
    @BindView(R.id.btn_main1_seckill_success_use)
    Button btn_main1_seckill_success_use;

    public SecKillSuccessDialog(Context context) {
        super(context);
    }

    @Override
    public View onCreateView() {
        //widthScale(0.85f);
        showAnim(new Tada());


        // dismissAnim(this, new ZoomOutExit());
        View inflate = View.inflate(mContext, R.layout.dialog_main1_seckill_success, null);
        ButterKnife.bind(this, inflate);
        return inflate;
    }

    @Override
    public void setUiBeforShow() {


        rl_main1_seckill_success_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });



        btn_main1_seckill_success_use.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                getVouchersInfo();
                dismiss();

            }
        });
    }





    //获取卡卷包信息
    public void getVouchersInfo() {



        //构造传输参数
        Map<String, String> map = new HashMap<String,String>();
        //0:未使用 1:已使用或过期
        map.put("isUse","0");
        map.put("size","20");
        map.put("page","0");

        //向服务器发送请求
        HttpUtils.HttpRequestByVollery(HttpUrls.URL, HttpActions.UserVouchersList, map,Volley.newRequestQueue(mContext), new HttpCallbackListener() {
            @Override
            public void onFinish(String response) {
                try {
                    JSONObject jsonObject = new JSONObject(response);

                    if (jsonObject.optInt("allCount") <= 0) {

                    }else {
                        Intent intent = new Intent(mContext,CardWrapActivity.class);
                        intent.putExtra("records",jsonObject.optString("records"));
                        mContext.startActivity(intent);
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                    AlertDialogUtils.showAlertDialog(mContext, mContext.getResources().getString(R.string.json_parse_error));
                }
            }

            @Override
            public void onError(VolleyError volleyError) {
                AlertDialogUtils.showAlertDialog(mContext, volleyError.getMessage());
            }
        });


    }


}
